package com.ruoyi.erpconfig.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erpconfig.domain.YyCompany;
import com.ruoyi.erpconfig.service.IYyCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用友公司配置Controller
 * 
 * @author ruoyi
 * @date 2022-12-21
 */
@RestController
@RequestMapping("/erpconfig/yy_company")
public class YyCompanyController extends BaseController
{
    @Autowired
    private IYyCompanyService yyCompanyService;

    /**
     * 查询用友公司配置列表
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:yy_company:list')")
    @GetMapping("/list")
    public TableDataInfo list(YyCompany yyCompany)
    {
        startPage();
        List<YyCompany> list = yyCompanyService.selectYyCompanyList(yyCompany);
        return getDataTable(list);
    }

    /**
     * 导出用友公司配置列表
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:yy_company:export')")
    @Log(title = "用友公司配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YyCompany yyCompany)
    {
        List<YyCompany> list = yyCompanyService.selectYyCompanyList(yyCompany);
        ExcelUtil<YyCompany> util = new ExcelUtil<YyCompany>(YyCompany.class);
        util.exportExcel(response, list, "用友公司配置数据");
    }

    /**
     * 获取用友公司配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:yy_company:query')")
    @GetMapping(value = "/{yyCompanyId}")
    public AjaxResult getInfo(@PathVariable("yyCompanyId") Long yyCompanyId)
    {
        return success(yyCompanyService.selectYyCompanyByYyCompanyId(yyCompanyId));
    }

    /**
     * 新增用友公司配置
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:yy_company:add')")
    @Log(title = "用友公司配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YyCompany yyCompany)
    {
        return toAjax(yyCompanyService.insertYyCompany(yyCompany));
    }

    /**
     * 修改用友公司配置
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:yy_company:edit')")
    @Log(title = "用友公司配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YyCompany yyCompany)
    {
        return toAjax(yyCompanyService.updateYyCompany(yyCompany));
    }

    /**
     * 删除用友公司配置
     */
    @PreAuthorize("@ss.hasPermi('erpconfig:yy_company:remove')")
    @Log(title = "用友公司配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{yyCompanyIds}")
    public AjaxResult remove(@PathVariable Long[] yyCompanyIds)
    {
        return toAjax(yyCompanyService.deleteYyCompanyByYyCompanyIds(yyCompanyIds));
    }
}
